<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>div水平垂直居中示例</title>
    <style>
        /* 通用样式 */
        .demo-container {
            margin: 20px 0;
            border: 1px solid #ccc;
            height: 200px;
            position: relative;
        }
        
        .demo-title {
            padding: 5px;
            background-color: #f0f0f0;
            font-weight: bold;
        }
        
        .center-box {
            background-color: #3498db;
            color: white;
            text-align: center;
            width: 100px;
            height: 100px;
        }
        /* 方法5: 绝对定位 + 四个方向0 + margin:auto */
        .method5 .center-box {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            margin: auto;
        }
    </style>
</head>
<body>
    <h3>方法5: 绝对定位 + 四个方向0 + margin:auto</h3>
    <div class="demo-container method5">
        <div class="center-box">微信公众号关注前端小歌谣</div>
    </div>
</body>
</html>